#ifndef _CODEGEN_HPP
#define	_CODEGEN_HPP

#include "ast.hpp"
#include "parser.hpp"
#include "analysis.hpp"
#include "instructions.hpp"

#include <iostream>


namespace codegen
{

using std::ostream;
using namespace ast;


class BinaryCodeGeneratorPass : public Visitor, public analysis::Pass {
public:
  BinaryCodeGeneratorPass(ostream& errors, ostream& out, int start_offset);

  void visit(Program&);

protected:
  void emit_instruction(Instruction& instr);
  void emit_data(Directive& dir);
  
  uint operand_payload(Instruction& instr);

  void emit_byte(uint n);
  void emit_word(uint n);

  ostream& output;
};


}

#endif
